package com.yixiu.javabase.modules.keyword._volatile;

/**
 *
 * Java中Volatile关键字详解 https://www.cnblogs.com/zhengbin/p/5654805.html
 * 下面的代码，在多线程时会出现问题。
 */
public class NoVisibility {

    private static boolean ready;
    private static int number;
    private static class ReaderThread extends Thread {
        @Override
        public void run() {
            while(!ready) {
                Thread.yield();
            }
            System.out.println(number);
        }
    }
    public static void main(String[] args) throws Exception {
        Thread t = new ReaderThread();
        t.start();
        t.join();

        number = 42;
        ready = true;




    }
}


